﻿using System.Collections.Generic;
using EPiMVC.Routing;
using Xunit;
using Xunit.Extensions;

namespace EPiMVC.Tests
{
    public class PathParserTests
    {
        [Theory]
        [InlineData("", new string[] { })]
        [InlineData("/", new string[] { })]
        [InlineData("//", new string[] { })]
        [InlineData("en", new[] { "en" })]
        [InlineData("/en", new[] { "en" })]
        [InlineData("en/", new[] { "en" })]
        [InlineData("/en/", new[] { "en" })]
        [InlineData("en/article", new [] { "en", "article" })]
        [InlineData("en/article/", new[] { "en", "article" })]
        [InlineData("?qs=1", new string[] { })]
        [InlineData("en/?qs=1", new [] { "en" })]
        [InlineData("/en/?qs=1", new[] { "en" })]
        [InlineData("/en?qs=1", new[] { "en" })]
        [InlineData("/a_", new[] { "a_" })]
        [InlineData("/a~", new[] { "a~" })]
        [InlineData("/a-", new[] { "a-" })]
        [InlineData("/123", new[] { "123" })]
        [InlineData("/en/?qs=/path", new[] { "en" })]
        public void GivenPath_GetUrlSegments_ReturnsCorrectListOfUrlSegments(string path, string[] expected)
        {
            List<string> result = PathParser.GetUrlSegments(path);

            for (int i = 0; i < expected.Length; i++)
                Assert.Equal<string>(expected[i], result[i]);
        }

        [Theory]
        [InlineData(new string[] {}, "")]
        [InlineData(new [] { "a" }, "/a/")]
        [InlineData(new [] { "a", "b" }, "/a/b/")]
        public void GivenUrlSegments_ToPath_ReturnsCorrectPath(IEnumerable<string> urlSegments, string expected)
        {
            string result = urlSegments.ToPath();

            Assert.Equal<string>(expected, result);
        }
    }
}
